from starlette.requests import Request
from fastapi import FastAPI,Form
from starlette.templating import Jinja2Templates

from starlette.responses import HTMLResponse
from starlette.responses import RedirectResponse
from starlette.staticfiles import StaticFiles
import time
import os,sys
import json
import datetime
app = FastAPI()
def runtime(func):
    def x():
        time0=time.time()
        result=func()
        time.sleep(2)
        time1=time.time()
        print('*********************************')
        print(time1-time0)
        return result
    return x

@app.get("/")
def read_root():
    #return {"Hello": "World"}
    return RedirectResponse(url='/login')

login0='''
<html>
<body>
<form name="input" action="/login" method="get">
<center><h2>Welcome</h2></center>
<center><br>Username: <input type="text" name="user"></br></center>
<center><br>Password: <input type="password" name="password"></br></center>
<center><br><input type="submit" value="Submit"></br></center>
</form>
</body>
</html>
'''


@app.get("/login")
def read_files(user:str=None, password:str=None):
    print("*******************1233")
    if user==None:
    #if item_id=='who':
        return HTMLResponse(content=login0)
    #print(item_id,user,password)
    if user=='admin' and password=='gi-de123':
        return RedirectResponse(url='/main1')
    else:
        return RedirectResponse(url='/')

    
@app.get("/main1")
def read_main():
    return {"Hello": "World"}